﻿using System.Windows;
using DevExpress.Xpf.Docking;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Prism.Regions.Behaviors;
using Microsoft.Practices.Unity;

namespace Oddo.Concept.Crm.Common.Presentation.Infrastructure
{
    public class TabbedGroupRegionBehavior : RegionBehavior, IHostAwareRegionBehavior
    {
        [Dependency]
        public IRegionManager RegionManager { get; set; }
        
        public DependencyObject HostControl { get; set; }
        
        protected override void OnAttach()
        {
            RegisterRegion();
        }
        void RegisterRegion()
        {
            DependencyObject targetElement = HostControl;
            if (targetElement.CheckAccess())
            {
                var tg = targetElement as TabbedGroup;
                if (tg != null && RegionManager != null)
                    RegionManager.Regions.Add(Region);
            }
        }
    }
}